/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package es.us.gestortareas.bean;

import es.us.gestortareas.entity.Tarea;
import es.us.gestortareas.entity.Usuario;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author master
 */
@Stateless
public class TareaFacade extends AbstractFacade<Tarea> {
    @PersistenceContext(unitName = "SistemaInformacion-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TareaFacade() {
        super(Tarea.class);
    }
    
    public List<Tarea> getMisTareas(Usuario u){
        List<Tarea> res = null;
        Query q = em.createNamedQuery("Tarea.misTareas");
        q.setParameter("usuario", u);        
        try{
            res = q.getResultList();            
        }catch(NoResultException e){            
        }        
        return res;
    }
    
    public Tarea crearTarea(Tarea t){        
        return em.merge(t);        
    }        
    
}
